package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

@Service

public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements EmpService {


    @Override
    public PageResult<Emp> getPageResult(EmpQueryParam param) {

        // 创建分页模型对象，设置页码和每页数量
        Page<Emp> page = new Page<>(param.getPage(), param.getPageSize());

        // 添加排序条件：根据最后修改时间倒序
     page.addOrder(OrderItem.desc("update_time"));





        // 调用从父类里继承来的page方法完成分页查询
        page = page(page);


        //     封装结果并返回
        return  new PageResult<>(page.getTotal(), page.getRecords());
    }
}
